package sample.pages;

import org.dreamwork.jasmine2.events.EventException;
import org.dreamwork.jasmine2.events.IClickListener;
import org.dreamwork.jasmine2.web.IWebControl;
import org.dreamwork.jasmine2.web.controls.Button;
import org.dreamwork.jasmine2.web.controls.DropdownList;
import org.dreamwork.jasmine2.web.controls.Page;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 11-1-1
 * Time: 上午2:10
 */
public class DropdownListTest extends Page {
    protected Map<String, String> current = new HashMap<String, String> ();
    protected List<Map<String, String>> list = new ArrayList<Map<String, String>> ();

    protected Button btn;

    protected DropdownList dropdownList;

    public DropdownListTest () {
        for (int i = 0; i < 5; i ++) {
            Map<String, String> map = new HashMap<String, String> ();
            map.put ("key", "value " + (i + 1));
            map.put ("text", "text " + (i + 1));
            list.add (map);
        }
    }

    @Override
    public void onPagePreload (Page page) throws EventException {
/*
        btn.addClickListener (new IClickListener() {
            public void onClick (IWebControl sender) throws EventException {
                onclick ();
            }
        });
*/
    }

    @Override
    public void onPageLoadCompleted (Page page) throws EventException {
        try {
            current.put ("value", "4");
            dataBind ();
        } catch (Throwable throwable) {
            throw new EventException (throwable);
        }
    }

    private void onclick () {
/*
        System.out.println (test.getSelectedIndex ());
        System.out.println (test.getSelectedValue ());
        System.out.println (test.getSelectedItem ());
*/
    }
}